home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / lcsum.c < prev    next >
C/C++ Source or Header  |  1991-02-25  |  920b  |  36 lines

  1. /* @(#) $Header: lcsum.c,v 1.4 91/02/24 20:17:11 deyke Exp $ */
  2.  
  3. /*
  4.  * Word aligned linear buffer checksum routine.  Called from mbuf checksum
  5.  * routine with simple args.  Intent is that this routine may be replaced
  6.  * by assembly language routine for speed if so desired. (On the PC, the
  7.  * replacement is in pcgen.asm.)
  8.  *
  9.  * Copyright 1991 Phil Karn, KA9Q
  10.  */
  11.  
  12. #if     (defined(MPU8086) || defined(MPU8080) || defined(vax))
  13. #define LITTLE_ENDIAN   /* Low order bytes are first in memory */
  14. #endif                  /* Almost all other machines are big-endian */
  15. #include "global.h"
  16. #include "ip.h"
  17.  
  18. int16
  19. lcsum(wp,len)
  20. register int16 *wp;
  21. register int16 len;
  22. {
  23.     register int32 sum = 0;
  24.     int16 result;
  25.  
  26.     while(len-- != 0)
  27.         sum += *wp++;
  28.     result = eac(sum);
  29. #ifdef  LITTLE_ENDIAN
  30.     /* Swap the result because of the (char *) to (int *) type punning */
  31.     result = (result << 8) | (result >> 8);
  32. #endif
  33.     return result;
  34. }
  35.  
  36.